﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;

    public class ClientDictionaryResultHandler<T> : IFromJson
    {
        private IDictionary<string, T> m_dict;

        public ClientDictionaryResultHandler(IDictionary<string, T> dict)
        {
            this.m_dict = dict;
        }

        bool IFromJson.CustomFromJson(JsonReader reader)
        {
            return false;
        }

        void IFromJson.FromJson(JsonReader reader)
        {
            Dictionary<string, object> dictionary = reader.ReadDictionary();
            if (dictionary != null)
            {
                foreach (KeyValuePair<string, object> pair in dictionary)
                {
                    if (pair.Value is T)
                    {
                        this.m_dict[pair.Key] = (T) pair.Value;
                    }
                }
            }
        }
    }
}

